// 输出fileList.md 包含生成的资源, 文件名, 文件数量
class FileListPlugin {
  constructor(options = {}) {
    this.options = options;
    this.filename = options?.filename || "fileList.md";
  }
  apply(compiler) {
    compiler.hooks.emit.tap("FileListPlugin", (compilation, callback) => {
      let { assets } = compilation;
      let count = Object.keys(assets).length;
      let content = `## 本次打包共生成${count}个文件 \n \n`;
      for (let filename in assets) {
        content += `- ${filename} \n`;
      }
      compilation.assets[this.filename] = {
        source: () => content,
        size: () => content.length,
      };
    });
  }
}

exports = module.exports = FileListPlugin;
